<template>
  <div class="advanceSaleReview" style="padding: 10px">
    <dt-search ref="search" :label-width="90">
      <Button type="primary" style="margin-left: 8px" @click="exportExcel">导出excel</Button>
    </dt-search>
    <dt-grid ref="table" :page='page' :onFetch='onFetch' />
  </div>
</template>

<script>
  import Column from './components/salesRiskControlColumns'
  import store from "@/store";
  import { buildPage } from "@/router/buildPage.js";
  import advanceSaleMgr from "@/biz/advanceSaleReview/advanceSaleReview";
  import buildMgr from "@/biz/building";
  import toolApi from "@/biz/base/tool";
  import SearchOpt from './components/salesRiskSearch'

  export default {
    data() {
      return {
        loading: false,
        formValidate: {
          orgIds: [],
          cityCode: "",
          housesName: "",
          status: "",
        },
        page: {
          total: 0,
        },
      };
    },
    created() {},
    mounted() {
      this.$refs.table.init(this, new Column())
      this.$refs.search.init(this.$refs.table, new SearchOpt())
      this.$refs.table.fetch()
    },
    methods: {
      onFetch(data) {
        this.formValidate = data
        this.formValidate.cityCode = data.city ? data.city[1] : ''
        delete this.formValidate.city
        return advanceSaleMgr.saleRiskCtlList(this.formValidate).then(res => {
          this.page.total = res.total
          return res.list
        })
      },
      exportExcel() {
        let params = this.formValidate
        toolApi.downloadCenter(
          "/dt-building/building/loadDownRiskCtlList",
          params
        );
      },
      getHouseList(val) {
        let params = {
          housesId: val.housesId,
        };
        advanceSaleMgr.houseList(params).then((res) => {
          buildMgr.updateBuildInfo(res.list[0]);
          this.$tool.setStorage({
            caseBuildingId: JSON.stringify(res.list[0].housesId),
          });
          store.dispatch("setRouterList", buildPage);
          this.$router.push({
            path: "/buildingHome/statistics",
          });
        });
      },
    },
  };
</script>

<style lang="scss" scoped>
  .channel-audit {
    padding: 20px;
  }

  .searchBox {
    padding: 20px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }
</style>